<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>活动管理</el-breadcrumb-item>
      <el-breadcrumb-item>活动列表</el-breadcrumb-item>
      <el-breadcrumb-item>活动详情</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card class="box-card">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-input v-model="goodslist.query" @input="search">
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getlist()"
            ></el-button>
          </el-input>
        </el-col>
        <el-col :span="18">
          <el-button type="primary" @click="$router.push('/goods_add')">添加</el-button>
        </el-col>
      </el-row>
      <el-table :data="tableData" border>
        <el-table-column type="index" label="#"> </el-table-column>
        <el-table-column prop="goods_name" label="商品名称"> </el-table-column>
        <el-table-column prop="goods_price" label="商品价格"> </el-table-column>
        <el-table-column prop="goods_number" label="商品重量">
        </el-table-column>
        <el-table-column  label="创建时间">
            <template slot-scope="scope">
                <div>
                  {{scope.row.upd_time|time}}
                </div>
            </template>
        </el-table-column>
             
        <el-table-column fixed="right" label="操作">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-edit"
            ></el-button>
            <el-button
              type="danger"
              size="mini"
              icon="el-icon-delete"
              @click="del(scope.row.goods_id)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>

 <div class="block">
    <span class="demonstration">完整功能</span>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="goodslist.pagenum"
      :page-sizes="[2,4,6,8]"
      :page-size="goodslist.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
      <!-- 添加 -->

      <!-- Form -->
      <el-dialog title="收货地址" :visible.sync="goodsaddlog">
        <el-form :model="form">
          <el-form-item label="活动名称" :label-width="formLabelWidth">
            <el-input v-model="form.name" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="goodsaddlog = false">取 消</el-button>
          <el-button type="primary" @click="goodsaddlog = false"
            >确 定</el-button
          >
        </div>
      </el-dialog>
    </el-card>
  </div>
</template>


<script>
import { goodslistapi, goodsdellist } from "@/http/api";
import _ from "lodash";
export default {
  data() {
    return {
      total:0,
      tableData: [],
      goodslist: {
        query: "",
        pagenum: 1,
        pagesize: 5,
      },
      form: {},
      goodsaddlog: false,
      formLabelWidth: "90px",
    };
  },
  created() {
    this.getlist();
  },
  methods: {
    handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.goodslist.pagesize=val
        this.getlist()
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.goodslist.pagenum=val
        this.getlist()
      },
    del(id) {
      console.log(id);
      goodsdellist(id).then((res) => {
        console.log(res);
        this.getlist();
      });
   
    },
    async getlist() {
      const res = await goodslistapi(this.goodslist);
      console.log("goods", res);
      this.tableData = res.goods;
      this.total=res.total
    },
    search: _.debounce(function () {
      this.getlist();
    }, 500),
  },
};
</script>

<style lang="scss" scoped>
.el-breadcrumb {
  margin-top: 20px;
}
.el-card {
  margin-top: 20px;
}
.el-tag {
  margin: 10px 10px;
}
.el-table {
  margin-top: 20px;
}
</style>